<template>
<div>
  <h1>商品展示</h1>
  <table border="1" cellspacing="0" align="center">
    <tr>
      <td>商品</td>
      <td>价格</td>
      <td>重量</td>
      <td>价钱</td>
      <td>数量</td>
      <td>操作</td>
    </tr>
    <tr v-for="i in shops">
      <td>{{i.name}}</td>
      <td><img :src="'http://127.0.0.1:8000'+i.pic" alt="" width="85px"></td>
      <td>{{i.weight}}</td>
      <td>{{i.price}}</td>
      <td>
        <button @click="kks(2,i.id)">-</button>
        {{i.number}}
        <button @click="kks(1,i.id)">+</button>
      </td>
      <td>
        <button @click="sc(i.id)">收藏</button>
      </td>
    </tr>
  </table>
  <button v-for="i in numms" @click="buy(i)">{{i}}</button>
</div>
</template>

<script>
export default {
  name: "mhsop",
  data(){
    return{
      shops:[],
      numms:'',

    }
  },
  methods:{
    kks(kk,id){
      this.$axios.put('users/MshopAPI/?kk='+kk +'&?id='+id)
      .then(res=>{
        // this.shops = res.data.list
        this.buy(1)
      })
    },
    buy(i){
      this.$axios.get('users/MshopAPI/?cpage='+i )
      .then(res=>{
        this.shops = res.data.list
        this.numms = res.data.numms
      })
    },
    sc(id){
      if (localStorage.getItem('userid')){
        // this.$axios.post('')
        alert('ok')
      }else {
        this.$router.push({path:'/mdl'})
      }
    }
  },
  mounted() {
    this.buy(1)
    this.kks()
    // localStorage.setItem('userid','')
  }
}
</script>

<style scoped>

</style>
